﻿var Tecnosop = Tecnosop || {};

Tecnosop.validateRut = function (value) {
//    if (value == null) return true; 
    var rut = value.split('-');

    var T = rut[0];
    var digito = rut[1];
    var M = 0, S = 1;

    for (; T; T = Math.floor(T / 10))
        S = (S + T % 10 * (9 - M++ % 6)) % 11;

    return S ? digito == S - 1 : digito == 'k';// || digito == 'K';
};

$.validator.addMethod("rut_validator", function (value, element) {
    return Tecnosop.validateRut(value);
});

$.validator.unobtrusive.adapters.addBool('Rut', 'rut_validator');